import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfo } from '@/api/admin/user'
import { removeToken } from '@/composables/cookie'

export const useUserStore = defineStore('user', () => {
  // 用户信息
  const userInfo = ref({})

  // 设置用户信息
  const setUserInfo = async ()=> {
    // 调用后头获取用户信息接口
    const res = await getUserInfo()
    if (res.success == true) {
      console.log(res);
      
        userInfo.value = res.data
    }
  }
  const logout = () => {
    removeToken()
    userInfo.value = {}
  }

  return { userInfo, setUserInfo, logout }
},
{
  // 开启持久化
  persist: true,
}
)
